/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.listener;

import com.minierp.dao.EnterpriseInfoDao;
import com.minierp.helper.EncCommonHelper;
import com.minierp.listener.FileUploadThread;
import com.minierp.model.EnterpriseInfo;
import java.io.File;
import java.io.FileInputStream;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class FileUploadListener extends HttpServlet {
	private FileUploadThread t;

	public void init() throws ServletException {
		super.init();
		ServletContext ct = this.getServletContext();
		String appPath = ct.getRealPath("/");
		if (!appPath.endsWith(File.separator)) {
			appPath = appPath + File.separator;
		}

		String filePath = appPath + "WEB-INF" + File.separator
				+ "system.property";
		FileInputStream in = null;

		File wac;
		try {
			wac = new File(filePath);
			in = new FileInputStream(wac);
			EncCommonHelper.loadProperties(in);
		} catch (Exception arg34) {
			;
		} finally {
			try {
				if (in != null) {
					in.close();
				}
			} catch (Exception arg30) {
				;
			}

		}

		filePath = appPath + "WEB-INF" + File.separator + "version.property";
		in = null;

		try {
			wac = new File(filePath);
			in = new FileInputStream(wac);
			EncCommonHelper.loadProperties(in);
		} catch (Exception arg32) {
			;
		} finally {
			try {
				if (in != null) {
					in.close();
				}
			} catch (Exception arg29) {
				;
			}

		}

		WebApplicationContext wac1 = WebApplicationContextUtils
				.getWebApplicationContext(this.getServletContext());
		EnterpriseInfoDao entDao = (EnterpriseInfoDao) wac1
				.getBean("enterpriseInfoDao");
		EnterpriseInfo ent = entDao.get();
		EncCommonHelper.setSmsInfo(ent.getSmsCode(), ent.getSmsPwd(),
				ent.getSmsKey(), ent.getSmsClientType());
		DataSource ds = (DataSource) wac1.getBean("dataSource");

		try {
			EncCommonHelper.checkLicense(appPath, ds);
		} catch (Exception arg31) {
			;
		}

		this.t = new FileUploadThread(this.getServletContext(),
				ent.getUploadPort());
		this.t.start();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) {
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) {
	}

	public void destroy() {
		this.t.socketClose();
	}
}